package workflow

import (
	"fmt"
	"runtime"
	"strings"
)

type Map map[string]any

type Flow interface {
	GetName() string
	Run(trigger FlowTrigger, data Map) error
	Rollback(trigger FlowRollback, data Map) error
	Skip(data Map) bool // default: func (f *xxx) Skip(data Map) bool {return false}
}

func GetName() string {
	pc, file, line, ok := runtime.Caller(1)
	if !ok {
		return ""
	}

	l := runtime.FuncForPC(pc).Name()

	ls := strings.SplitN(l, "/", 2)
	if len(ls) > 0 {
		if idx := strings.Index(file, ls[0]); idx != -1 {
			file = file[idx:]
		}
	}

	return fmt.Sprintf("%s@%s:%d", l, file, line)
}
